package com._1.message.rabbitMq;

import com._1.message.rabbitMq_order.RabbitMqOrderConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

//    public void sendMsg(String queueName,String msg){
//        // 发送消息到广播交换器，路由键为空（广播交换器忽略路由键）
//        rabbitTemplate.convertAndSend(queueName, "", msg);
//        System.out.println("发送消息：" + msg);
//
//
//
//    }

    public void sendOrderMsg(String msg){
        // 订单队列
        rabbitTemplate.convertAndSend(RabbitMqOrderConfig.ORDER_EXCHANGE_NAME, RabbitMqOrderConfig.ORDER_ROUTING_KEY, msg);
        System.out.println("订单消息已发送到队列 " + RabbitMqOrderConfig.ORDER_QUEUE_NAME + "： " + msg);
    }
}
